home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / plane arcade / planearcade.exe / tank3.bmp / main.cpp < prev    next >
C/C++ Source or Header  |  2004-09-28  |  12KB  |  528 lines

  1.  
  2.  
  3. #include "main.h"
  4.  
  5. //--------------------------
  6. //Globals
  7. //--------------------------
  8. DXFONT DFont;
  9.  
  10. MODEL SkyBoxSide;
  11. MODEL SkyBoxTop;
  12.  
  13. SOUND MenuMusic;
  14. SOUND GameMusic;
  15. float MenuMusicTime = -1.0f;
  16. float GameMusicTime = -1.0f;
  17.  
  18. //--------------------------
  19. //Funkcie
  20. //--------------------------
  21. void InitializeScene();
  22. void DestroyScene();
  23.  
  24. void SetProjectionScene();
  25. void SetProjectionSkyBox();
  26.  
  27. //-----------------------------------------------------------------------------
  28. // Name: Render()
  29. // Desc: Draws the scene
  30. //-----------------------------------------------------------------------------
  31. VOID Render()
  32. {
  33.  
  34.     //begin
  35.     Engine.BeginScene();
  36.  
  37.     //ovladanie 
  38.     Input.RefreshKeyboard();
  39.     Input.RefreshMouse();
  40.  
  41.     //obnov svetla
  42.     LightManager.RefreshLights();
  43.  
  44.     ////////
  45.     //Menu//
  46.     ////////
  47.     if (Menu.EnabledMenu == true)
  48.     {
  49.         //hudba
  50.         if (GameMusicTime != -1.0f)
  51.         {
  52.             GameMusic.Stop();
  53.             GameMusicTime = -1.0f;
  54.         }
  55.         if (MenuMusicTime == -1.0f && MusicEnabled)
  56.         {
  57.             MenuMusicTime = 0.0f;
  58.         }
  59.         if (MenuMusicTime == 0.0f && MusicEnabled)
  60.         {
  61.             MenuMusic.Play(true);
  62.         }
  63.         MenuMusicTime += PowerTime(0.01f);
  64.         if (MenuMusicTime > 295.0f && MusicEnabled)
  65.         {
  66.             MenuMusicTime = 0.0f;
  67.         }
  68.         
  69.         
  70.         //skry kurzor
  71.         ShowCursor(false);
  72.  
  73.         //obnovi menu
  74.         Menu.Refresh();
  75.  
  76.     }
  77.  
  78.     /////////////
  79.     //Briefring//
  80.     /////////////
  81.     float zFPS = FPS;  //pre casovanie hudby
  82.     if (Menu.EnabledBriefring == true)
  83.     {
  84.         //zvysi FPS - zastavi hru
  85.         FPS = 160000.0f;
  86.     }
  87.         
  88.     ////////
  89.     //Svet//
  90.     ////////
  91.     if (Menu.EnabledMenu == false)
  92.     {
  93.         //hudba
  94.         if (MenuMusicTime != -1.0f)
  95.         {
  96.             MenuMusic.Stop();
  97.             MenuMusicTime = -1.0f;
  98.         }
  99.         if (GameMusicTime == -1.0f && MusicEnabled)
  100.         {
  101.             GameMusicTime = 0.0f;
  102.         }
  103.         if (GameMusicTime == 0.0f && MusicEnabled)
  104.         {
  105.             GameMusic.Play(true);
  106.         }
  107.         GameMusicTime += (1000.0f/zFPS) * 0.01f;
  108.         if (GameMusicTime > 400.0f && MusicEnabled)
  109.         {
  110.             GameMusicTime = 0.0f;
  111.         }
  112.     
  113.         //Pridavanie objektov
  114.         Level.ProccesLevel();
  115.  
  116.         //spitfire
  117.         SpitFire.Refresh();
  118.  
  119.         //nastavi projekcnu maticu pre skybox
  120.         SetProjectionSkyBox();
  121.  
  122.         //skybox
  123.         SkyBoxSide.Pos = Camera.Pos;
  124.         SkyBoxSide.Pos.Y = 2800.0f;
  125.         SkyBoxSide.Render();
  126.         
  127.         SkyBoxTop.Pos = Camera.Pos;
  128.         SkyBoxTop.Pos.Y = 2700.0f;
  129.         SkyBoxTop.Render();
  130.  
  131.         //nastavi projektcnu maticiu pre scenu
  132.         SetProjectionScene();
  133.  
  134.         //krajina
  135.         Level.Refresh();
  136.  
  137.         //renderspitfire
  138.         SpitFire.Render();
  139.  
  140.         //explozie
  141.         Explo.Render();
  142.  
  143.         //vyrenderuj skore napisy
  144.         Score.Refresh();
  145.  
  146.         //vyrenderuje gui
  147.         Menu.DrawGui();
  148.  
  149.         //vyrenderuje mapu
  150.         Menu.DrawMap();
  151.  
  152.         //oznamy
  153.         SpitFire.DrawScreens(); 
  154.  
  155.         //skry kurzor
  156.         ShowCursor(false);
  157.  
  158.         //debug font
  159.         if (SpitFire.ShowFPS)
  160.         {
  161.             char cBuf[80];
  162.             sprintf(cBuf,"FPS: %d",iFPS);
  163.             DFont.Print(20,20,GetColor(1.0f,1.0f,0.0f,0.0f),cBuf);
  164.         }
  165.     
  166.     }
  167.  
  168.     /////////////
  169.     //Briefring//
  170.     /////////////
  171.     if (Menu.EnabledBriefring == true)
  172.     {
  173.         //zobrazi briefring
  174.         Menu.RefreshBriefring();
  175.  
  176.     }
  177.  
  178.     //!!Tento problem vystava iba pri nastaveni grafickej karty
  179.     //!!na slaby vykon, alebo je to tiez dobre kedze na zaciatku
  180.     //!!sa nacitava briefing
  181.     //!!Hack, zoberie silu
  182.     float Power;
  183.     Power = PowerTime(0.001f);
  184.  
  185.     //end
  186.     Engine.EndScene();
  187.  
  188.     //!!Hack ak stagetime == 0.0f+power FPS zvysit!!
  189.     if (Level.StageTime == 0.0f+Power && Menu.EnabledMenu == false)
  190.         FPS = 120.0f;
  191. }
  192.  
  193. //-----------------------------------------------------------------------------
  194. // Name: MsgProc()
  195. // Desc: The window's message handler
  196. //-----------------------------------------------------------------------------
  197. LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  198. {
  199.     switch( msg )
  200.     {
  201.         case WM_DESTROY:
  202.             PostQuitMessage( 0 );
  203.             return 0;
  204.     }
  205.  
  206.     return DefWindowProc( hWnd, msg, wParam, lParam );
  207. }
  208.  
  209.  
  210.  
  211.  
  212. //-----------------------------------------------------------------------------
  213. // Name: WinMain()
  214. // Desc: The application's entry point
  215. //-----------------------------------------------------------------------------
  216. INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
  217. {
  218.     // Register the window class
  219.     WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
  220.                       GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
  221.                       WinClassName, NULL };
  222.     RegisterClassEx( &wc );
  223.  
  224.  
  225.     //zaciatok logu
  226.     LogStart();
  227.  
  228.     //info o programe
  229.     LogPrint(ProgramInfo);
  230.  
  231.     ///////////////////////
  232.     //PRECITAJ NASTAVENIA//
  233.     ///////////////////////
  234.     ReadConfigData();
  235.  
  236.     ////////////////////////
  237.     //MENITELNE NASTAVENIA//
  238.     ////////////////////////
  239.     
  240.     //SetUp Resotution
  241.     if (Resolution == 0)
  242.     {
  243.         Engine.Width = 640;
  244.         Engine.Height = 480;
  245.     }
  246.     if (Resolution == 1)
  247.     {
  248.         Engine.Width = 800;
  249.         Engine.Height = 600;
  250.     }
  251.     if (Resolution == 2)
  252.     {
  253.         Engine.Width = 1024;
  254.         Engine.Height = 768;
  255.     }
  256.  
  257.     //SetUp Engine
  258.     Engine.Windowed = false;
  259.     Engine.Format =  D3DFMT_X8R8G8B8;
  260.     Engine.TextureFormat = D3DFMT_A8R8G8B8;
  261.     Engine.Min = 10.0f;
  262.     Engine.Max = (float)DrawDistance;
  263.     Engine.BackColor = GetColor(1.0f,1.0f,1.0f,1.0f);
  264.  
  265.     //nastav frustrum culling camery
  266.     Camera.MaxDis = (float)DrawDistance;
  267.  
  268.     //stencil tiene
  269.     if (Shadows == 0)
  270.         Engine.StencilShadows = false;
  271.     else if (Shadows == 1)
  272.         Engine.StencilShadows = true;
  273.  
  274.  
  275.     ////////////////////////////
  276.     //nastav okno pre windowed//
  277.     ////////////////////////////
  278.     if(Engine.Windowed == true)
  279.     {
  280.         hWnd = CreateWindow( WinClassName, WinClassTittle,
  281.                               WS_OVERLAPPEDWINDOW,
  282.                               100, 100,Engine.Width, Engine.Height,
  283.                               GetDesktopWindow(), NULL, wc.hInstance, NULL );
  284.     }
  285.  
  286.     //////////////////////////////
  287.     //nastav okno pre fullscreen//
  288.     //////////////////////////////
  289.     if(Engine.Windowed == false)
  290.     {
  291.          hWnd = CreateWindowEx(    WS_EX_APPWINDOW,        // Extended Style For The Window
  292.                                 WinClassName,            // Class Name
  293.                                 WinClassTittle,    // Window Title
  294.                                 WS_POPUP |            // Defined Window Style
  295.                                 WS_CLIPSIBLINGS |    // Required Window Style
  296.                                 WS_CLIPCHILDREN,    // Required Window Style
  297.                                 0, 0,                // Window Position
  298.                                 Engine.Width,        // Calculate Window Width
  299.                                 Engine.Height,        // Calculate Window Height
  300.                                 NULL,                // No Parent Window
  301.                                 NULL,                // No Menu
  302.                                 wc.hInstance,        // Instance
  303.                                 NULL);                // Dont Pass Anything To WM_CREATE
  304.     }
  305.  
  306.  
  307.     
  308.     hIns = hInst;
  309.  
  310.     
  311.     ////////////////////////////////////
  312.     //Nastavenia ktore sa nedaju menit//
  313.     ////////////////////////////////////
  314.  
  315.     //Initialize engine
  316.     Engine.Initialize();
  317.     Engine.SetZBuffer(true);
  318.     Engine.SetFilter(0,D3DTEXF_LINEAR);
  319.     Engine.SetFilter(1,D3DTEXF_LINEAR);
  320.     Engine.SetCullMode(D3DCULL_NONE);
  321.     Engine.SetShadeMode(D3DSHADE_GOURAUD);    
  322.  
  323.     Engine.SetMipMapping(0,true);
  324.     Engine.SetMipMapping(1,true);
  325.     Engine.MipMapLevels = 0;
  326.  
  327.     //directInput
  328.     Input.Initialize();
  329.  
  330.     //zvuk
  331.     InitializeSound();
  332.  
  333.     //zobrazi okno
  334.     ShowWindow( hWnd, SW_SHOWDEFAULT );
  335.     UpdateWindow( hWnd );
  336.  
  337.     //vstup do Message slucky
  338.     MSG msg;
  339.     ZeroMemory( &msg, sizeof(msg) );
  340.  
  341.     //inicializacia svetiel pre lightmanager
  342.     LightManager.Initialize(1);
  343.  
  344.     //debug font 
  345.     DFont.Create(15,FW_BOLD,"Arial");
  346.  
  347.     //editor
  348.     Editor.Initialize();
  349.  
  350.     ///////////////////////
  351.     //Inicializacia Sceny//
  352.     ///////////////////////
  353.     InitializeScene();
  354.     
  355.     ////////////////
  356.     //message loop//
  357.     ////////////////
  358.     while( msg.message!=WM_QUIT )
  359.     {
  360.        if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
  361.        {
  362.            TranslateMessage( &msg );
  363.            DispatchMessage( &msg );
  364.        }
  365.        else
  366.        {
  367.           Render();
  368.           //Editor.RefreshEditor();
  369.        }
  370.     }
  371.  
  372.     /////////////////
  373.     //Destroy sceny//
  374.     /////////////////
  375.  
  376.     //znic level
  377.     Level.Destroy();
  378.  
  379.     //vymaze svetla
  380.     LightManager.CleanUp();
  381.  
  382.     //ukonci direct Input
  383.     Input.CleanUp();
  384.  
  385.     //ukonci zvuk
  386.     CleanUpSound();
  387.  
  388.     //Ukonci Engine
  389.     Engine.CleanUp(); 
  390.  
  391.     //znici okno
  392.     UnregisterClass( WinClassName, wc.hInstance );
  393.     return 0;
  394. }
  395.  
  396. //-----------------------------------------------------------------------------
  397. // Name: InitializeScene()
  398. // Desc: nastavy krajinu, svetla, ..
  399. //-----------------------------------------------------------------------------
  400. void InitializeScene()
  401. {
  402.  
  403.     //nastav menu
  404.     //---------------
  405.     Menu.Initialize();
  406.  
  407.     //skore
  408.     //-----
  409.     Score.Initialize();
  410.  
  411.     //Svetla
  412.     //------
  413.     LightManager.AddLightDir(Get3D(1.5f,-1.0f,1.5f),GetColor(1.6f,1.6f,1.6f,1.6f),
  414.                                                     GetColor(0.3f,0.3f,0.3f,0.3f),
  415.                                                     GetColor(1.0f,1.0f,1.0f,1.0f));
  416.  
  417.     //Hmla
  418.     //----
  419.     g_pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, 0xffffffff );
  420.  
  421.     g_pd3dDevice->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
  422.     g_pd3dDevice->SetRenderState(D3DRS_FOGSTART, FtoDW((float)DrawDistance*0.50f));
  423.     g_pd3dDevice->SetRenderState(D3DRS_FOGEND,   FtoDW((float)DrawDistance*0.75f));
  424.     
  425.     
  426.     //skyBox
  427.     //--------
  428.     Menu.DrawLoading(1,"Loading SkyBox");
  429.  
  430.     
  431.     SkyBoxSide.FrustrumTest = false;
  432.     SkyBoxSide.Lighting = false;
  433.     SkyBoxSide.InitializeAse(1,"scene/skyboxside.ase");
  434.     SkyBoxSide.LoadAse(0,"scene/skyboxside.ase");
  435.     SkyBoxSide.LoadTexture("scene/skySide.jpg",GetColor(0.0f,0.0f,0.0f));
  436.     SkyBoxSide.Sca = Get3D(250.0f,150.0f,250.0f);
  437.  
  438.     SkyBoxTop.FrustrumTest = false;
  439.     SkyBoxTop.Lighting = false;
  440.     SkyBoxTop.InitializeAse(1,"scene/skyboxTop.ase");
  441.     SkyBoxTop.LoadAse(0,"scene/skyboxTop.ase");
  442.     SkyBoxTop.LoadTexture("scene/skyTop.jpg",GetColor(0.0f,0.0f,0.0f));
  443.     SkyBoxTop.Sca = Get3D(250.0f,150.0f,250.0f);
  444.     
  445.     //stencil
  446.     //------------
  447.     Menu.DrawLoading(1,"Initalizing StencilShadow");
  448.  
  449.     StencilShadow.Initialize();
  450.         
  451.     //modely
  452.     //------
  453.     Menu.DrawLoading(2,"Loading Models");
  454.  
  455.     ModelLib.Initialize();
  456.  
  457.     //zvuky
  458.     //-----
  459.     Menu.DrawLoading(4,"Loading Sounds");
  460.  
  461.     SoundLib.Initialize();
  462.  
  463.     //SpitFire
  464.     //--------------
  465.     Menu.DrawLoading(5,"Loading SpitFire");
  466.  
  467.     SpitFire.Initialize();
  468.  
  469.     //svet
  470.     //-----
  471.     Menu.DrawLoading(6,"Initializing World");
  472.  
  473.     Level.Initialize();
  474.     
  475.     //Particles
  476.     //------------
  477.     Menu.DrawLoading(8,"Initializing Particle Systems");
  478.  
  479.     Explo.Initialize();
  480.  
  481.     //Hudba
  482.     //---------
  483.     if (MusicEnabled == 1)
  484.     {
  485.         MenuMusic.InitialiseForMP3();
  486.         MenuMusic.LoadSound("sounds/menumusic.mp3");
  487.         GameMusic.InitialiseForMP3();
  488.         GameMusic.LoadSound("sounds/gamemusic.mp3");
  489.     }
  490.     
  491. }
  492.  
  493.  
  494. //-----------------------------------------------------------------------------
  495. // Name: DestroyScene()
  496. // Desc: znici krajinu
  497. //-----------------------------------------------------------------------------
  498. void DestroyScene()
  499. {
  500.  
  501.     //Svet
  502.     //----
  503.     Level.Destroy();
  504.  
  505. }
  506.  
  507. //-----------------------------------------------------------------------------
  508. // Name: SetProjectionScene()
  509. // Desc: nastavi projekcnu maticu pre renderovanie sceny
  510. //-----------------------------------------------------------------------------
  511. void SetProjectionScene()
  512. {
  513.     D3DXMatrixPerspectiveFovLH( &matProj, 4.0f/3.0f,1.0f,Engine.Min, Engine.Max);
  514.     g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
  515. }
  516.  
  517. //-----------------------------------------------------------------------------
  518. // Name: SetProjectionSkyBox()
  519. // Desc: nastavi projekcnu maticu pre renderovanie skyboxu
  520. //-----------------------------------------------------------------------------
  521. void SetProjectionSkyBox()
  522. {
  523.     D3DXMatrixPerspectiveFovLH( &matProj, 4.0f/3.0f, 1.0f,Engine.Min, 25000);
  524.     g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
  525. }
  526.  
  527.  
  528.